﻿/*----------------------------------------------------------------
    // Copyright (C) 2009 江苏华招网
    // 版权所有。 
    // 作者：吕海乐 
    //
    // 文件名：BidProductPriceUpdate.cs
    // 文件功能描述：采购产品管理：修改采购产品价格
    // 创建标识：吕海乐2009-03-24
    //
    // 修改标识：
    // 修改描述：
    //
    // 修改标识：
    // 修改描述：
    //
    // 审核人：页面作废 2009-6-4 李刚
// 审核时间：
// 审核说明：
 //----------------------------------------------------------------*/
using System;
using System.Collections;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Collections.Generic;
using HZ.DrugTrade.Web;
using HZ.DrugTrade.Model;
using HZ.DrugTrade.Model.Enum;
using HZ.DrugTrade.IBLL;
using HZ.DrugTrade.BLLFactory;

namespace HZ.DrugTrade.Web.Admin
{
    public partial class BidProductPriceUpdate : BasePage
    {
        IBLL_ProcurementBasic ipb = Factory.BLL_ProcurementBasic();
        private decimal OriginalPrice;
        public BidProductPriceUpdate()
        {
            this.ModuleNo = Module.采购产品管理.ToString();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            //获取需要修改的产品的相关信息
            if (!this.IsPostBack)
            {
                if (Request["procureCatalogId"] != null)
                {
                    string procureCatalogId = Request["procureCatalogId"].ToString();

                    Model.Query.ProcureCatalog procureCatalog = new HZ.DrugTrade.Model.Query.ProcureCatalog();
                    procureCatalog.ProcureCatalogID = procureCatalogId;
                    procureCatalog.SortFields = " ProductName asc";

                    try
                    {
                        AspNetPager1.PageSize = 5;
                        int totalCount = 0;
                        IList<Model.View.ProcureCatalog> procureCatalogList = ipb.GetProcureCatalogByWhere(procureCatalog, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out totalCount);
                        AspNetPager1.RecordCount = totalCount;
                        gvwCatalogInfo.DataSource = procureCatalogList;
                        gvwCatalogInfo.DataBind();

                        //获取产品的原始价格
                        TextBox txt = (TextBox)gvwCatalogInfo.Rows[0].Cells[8].FindControl("txtProcurePrice");
                        if (!string.IsNullOrEmpty(txt.Text.Trim()))
                        {
                            OriginalPrice = Convert.ToDecimal(txt.Text.Trim());
                        }
                    }
                    catch (Exception ex)
                    {
                        PageError(ex.Message, "BidProductList.aspx");
                    }
                }
                else
                {
                    PageError("你还未选中需要修改的产品！", "BidProductList.aspx");
                }
            }
        }

        private void PriceUpdate()
        {
            ProcureCatalog procureCatalog = new ProcureCatalog();
            TextBox txt = (TextBox)gvwCatalogInfo.Rows[0].Cells[8].FindControl("txtProcurePrice");
            if (!string.IsNullOrEmpty(txt.Text.Trim()))
            {
                procureCatalog.ProcurePrice = Convert.ToDecimal(txt.Text.Trim());
            }
            procureCatalog.ProcureCatalogID = Request["procureCatalogId"].ToString();

            //获取操作日志信息
            Model.AdjustPriceLog log = new AdjustPriceLog();
            log.AdjustPrice = procureCatalog.ProcurePrice;
            User user = CurrentAccount.GetUser();
            log.AdjustPricePerson = user.UserName;
            log.AdjustPriceReason = txtReason.Text;
            if (!string.IsNullOrEmpty(txtDateTime.Text.Trim()))
            {
                log.AdjustPriceTime = Convert.ToDateTime(txtDateTime.Text.Trim());
            }
            log.OriginalPrice = OriginalPrice;
            log.PriceLogSerialID = Guid.NewGuid().ToString();
            log.ProcureCatalogID = procureCatalog.ProcureCatalogID;
            int flag = ipb.UpdateProcureCatalog_ProcurePrice(procureCatalog,log);
            if (flag == 0)
            {
                PageError("修改失败！", "");
            }
            else if (flag == 1)
            {
                PageInfo("修改成功！", this.ReturnUrl);
               
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            PriceUpdate();
        }
    }
}
